<script>
  jQuery(document).ready(function() {
    jQuery('#article_event_id').change(function(){  
                                // alert(jQuery(this).val());
                                id = jQuery(this).val();
                                
                                if(id != "")
                                {
                                  loading_area('<%= image_tag "loading_ajax.gif" %>', "#related-images", "#related-images");
                                  jQuery.ajax({
                                  url: '<%= url_for({:controller => 'images', :action => 'related_images'}) %>',
                                  data: "eventid="+id,
                                  success: function (data){
                                        jQuery('#related-images').html(data)
                                      }
                                }); 
                                }
                        });
  });
</script>

<%= form_for(@article, :url => {:controller => 'reporter_articles', :action => 'save', :id => @article.id}) do |f| %>
  <% if @article.errors.any? %>
	  <div class="notification errors closable">
		<h3><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h3>
		<ul>
			<% @article.errors.full_messages.each do |msg| %>				
				<li><%= msg %></li>
			<% end %>			
		</ul>
	<span title="Close" class="closelink"></span></div>      
  <% end %>
  
  
					<fieldset>
						<legend>Event</legend>
						
						
						  
		                                                
						    <%= select("article", "event_id", @events, {:include_blank => '== None =='}, :size => 4, :style => "width:500px") %>
						    
						    <div id="event-content"></div>
			
						  
						
					</fieldset>
					
					<fieldset>
						<legend>Details</legend>
						<h4>Please fill in the form.</h4>
						
						<% if !@event.nil? %>
							<input type="hidden" name="article[event_id]" value="<%= @event.id.to_s %>" />
						<% end %>
						
						<%= f.label :title %><%= f.text_field :title, :class => "medium" %>
						<p class="validation">
						*required</p>
						
						<%= f.label :channel %>
						<%= select("article", "channel_id", @channels, {}) %>
						<p class="validation">
						</p>
						
						<%= f.label :default_image %>
						<p>
						  <img width="100" src="<%= url_for({:controller => "images", :action => 'thumbnail', :id => @article.image_id, :size => "small"}) %>" border="0" id="default_image" />
						  <input type="hidden" id="article_image_id" name="article[image_id]" value="<%= @article.image_id %>" />
						</p>
						<a href="#related-images">Choose image</a>
						<p class="validation">
						</p>
						
						
						<%= f.label :body %><%= f.text_field :body, :class => "tinymce" %>
						<p class="validation">
						<!-- <a style="margin-top:25px;" id="insert-image-but" href="#modal-window" onclick='openInsertImage("<%= url_for(:action => 'insert_image_box', :id => "1") %>")' class='button gray'>Insert Images</a> -->
						*required						
						</p>						
						
						<!-- tinyMCE.execInstanceCommand("article_body","mceInsertContent",false,"sdfsdf"); -->
						
					</fieldset>

<% end %>